<template>
 <div style="width: 100%;height: 100%;padding: 16px 20px;">
    <div style="width: 400px;height: 100%;display: inline-block;float: right;border-radius: 5px;background-color: white;position: relative;">
      <div v-if="rightPageId==0" style="height: 100%;">
        <div style="padding: 20px 20px;border-bottom: 1px solid var(--color-neutral-4);position: relative;">
          菜单
        </div>
        <div style="padding: 10px 10px;height: calc(100% - 56.76px);width: 100%;overflow-y: scroll;">
          <div class="right-button" @click="rightPageId=1">
              添加专业
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32.556 24L16.293 7.737a1 1 0 010-1.415l1.414-1.414a1 1 0 011.414 0L36.8 22.586a2 2 0 010 2.828L19.121 43.092a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414L32.556 24z" fill="currentColor"/></svg>
          </div>
          <div class="right-button" @click="rightPageId=3">
              导入专业
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32.556 24L16.293 7.737a1 1 0 010-1.415l1.414-1.414a1 1 0 011.414 0L36.8 22.586a2 2 0 010 2.828L19.121 43.092a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414L32.556 24z" fill="currentColor"/></svg>
          </div>
          <div class="right-button" @click="rightPageId=4">
              删除选中的专业
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32.556 24L16.293 7.737a1 1 0 010-1.415l1.414-1.414a1 1 0 011.414 0L36.8 22.586a2 2 0 010 2.828L19.121 43.092a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414L32.556 24z" fill="currentColor"/></svg>
          </div>
          <div class="right-button" @click="rightPageId=5">
              删除全部专业
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32.556 24L16.293 7.737a1 1 0 010-1.415l1.414-1.414a1 1 0 011.414 0L36.8 22.586a2 2 0 010 2.828L19.121 43.092a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414L32.556 24z" fill="currentColor"/></svg>
          </div>
          <div class="right-button" @click="rightPageId=6">
              在线更新专业表
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M32.556 24L16.293 7.737a1 1 0 010-1.415l1.414-1.414a1 1 0 011.414 0L36.8 22.586a2 2 0 010 2.828L19.121 43.092a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414L32.556 24z" fill="currentColor"/></svg>
          </div>
        </div>
      </div>
      <div v-if="rightPageId==6" style="width: 100%;height: 100%;position: relative;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="()=>{
              if(isDeleting==false){
                rightPageId=0
              }
            }">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              在线更新专业表
        </div>
        <div style="padding: 20px 20px;">
          <p style="margin-bottom: 15px;">此操作将在线获取所有专业的信息并将其导入到专业表中。</p>
          <div style="text-align: right;width: 100%;">
            <a-button :loading="isOnlineRefreshing" style="padding: 0 30px;" type="primary" status="success" @click="onlineRefresh">更新</a-button>
          </div>
        </div>
      </div>
      <div v-if="rightPageId==5" style="width: 100%;height: 100%;position: relative;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="()=>{
              if(isDeleting==false){
                rightPageId=0
              }
            }">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              删除全部专业
        </div>
        <div style="padding: 20px 20px;">
          <p style="margin-bottom: 15px;">此操作将彻底删除全部专业且不可恢复。</p>
          <div style="text-align: right;width: 100%;">
            <a-button :loading="isDeleting" style="padding: 0 30px;" type="primary" status="danger" @click="deleteAll">删除</a-button>
          </div>
        </div>
      </div>
      <div v-if="rightPageId==4" style="width: 100%;height: 100%;position: relative;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="()=>{
              if(isDeleting==false){
                rightPageId=0
              }
            }">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              删除选中的专业
        </div>
        <div style="padding: 20px 20px;">
          <p style="margin-bottom: 15px;">此操作将彻底删除选中的专业且不可恢复。</p>
          <div style="text-align: right;width: 100%;">
            <a-button :loading="isDeleting" style="padding: 0 30px;" type="primary" status="danger" @click="deleteSelected">删除</a-button>
          </div>
        </div>
      </div>
      <div v-if="rightPageId==3" style="width: 100%;height: 100%;position: relative;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="rightPageId=0">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              导入专业
        </div>
        <div style="padding:20px 20px;width: 100%;height: calc(100% - 113px);overflow-y: scroll;">
          <div style="margin-bottom: 10px;line-height: 20px;">
            <p>表格文件要求</p>
                <p>1.专业数据应保存在表格文件的第一个表格中；</p>
                <p>2.表格的第一行应为每一列数据的标题，并且必须包括“专业名称”、“院校名称”、“专业代码”、“院校代码”、“{{ subtractFromCurrentYear(1) }}年计划投档数”、“{{ subtractFromCurrentYear(1) }}年最低分”、“{{ subtractFromCurrentYear(1) }}年投档最低位次”、“{{ subtractFromCurrentYear(2) }}年计划投档数”、“{{ subtractFromCurrentYear(2) }}年最低分”、“{{ subtractFromCurrentYear(2) }}年投档最低位次”、“{{ subtractFromCurrentYear(3) }}年计划投档数”、“{{ subtractFromCurrentYear(3) }}年最低分”、“{{ subtractFromCurrentYear(3) }}年投档最低位次”、“所在省”、“所在市”、“科目”、“学费”、“类型层次”和“批次”这几个标题；</p>
                <p>3.如果表格文件符合上面的要求但是不能正常导入，可能是表格内某些单元格的值过长造成的。</p>
          </div>
          <a-steps label-placement="horizontal" direction="vertical" :current="importMajorsCurrentStep">
                <a-step>选择Excel文件
                  <div>
                    <input style="font-size: 14px;" :disabled="importMajorsCurrentStep!=1" type="file" ref="upload" accept=".xls,.xlsx" class="outputlist_upload" @change="readExcel0">
                    <!-- <a-upload action="/api/v1/file/upload" :disabled="importMajorsCurrentStep!=1" @change="uploadFile"></a-upload> -->
                  </div>
                  <div v-if="importMajorsWarningText!='' && importUniversityStep==1" style="width: 100%;word-break: break-all;font-size: 14px;color: red;">
                    {{ importMajorsWarningText }}
                  </div>
                </a-step>
                <a-step>正在导入
                  <div v-if="importMajorsCurrentStep==2" style="font-size: 14px;">
                    <a-button :loading="true" style="background-color: white;color: black !important;font-size: 14px;cursor: unset !important;">{{'正在导入第' + currentImportFile + '个文件，已完成' + parseInt(importedMajorsNum/importMajorsNum*10000)/100 + '%'}}</a-button>
                  </div>
                </a-step>
                <a-step>完成导入
                  
                </a-step>
          </a-steps>
        </div>
      </div>
      <div  v-if="rightPageId==2" style="width: 100%;height: 100%;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="rightPageId=0">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              修改专业信息
        </div>
        <div style="width: 100%;padding: 20px 20px;height: calc(100% - 112px);overflow-y: scroll;">
          <div style="margin-bottom: 10px;">
            专业代码
            <a-input v-model="updateMajorForm.majorCode" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入专业代码" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            专业名称
            <a-input v-model="updateMajorForm.majorName" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入专业名称" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            院校代码
            <a-input v-model="updateMajorForm.universityCode" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入院校代码" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            院校名称
            <a-input v-model="updateMajorForm.universityName" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入院校名称" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年投档计划数
            <a-input v-model="updateMajorForm.num1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年最低分
            <a-input v-model="updateMajorForm.score1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年投档最低位次
            <a-input v-model="updateMajorForm.ranking1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年投档计划数
            <a-input v-model="updateMajorForm.num2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年最低分
            <a-input v-model="updateMajorForm.score2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年投档最低位次
            <a-input v-model="updateMajorForm.ranking2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年投档计划数
            <a-input v-model="updateMajorForm.num3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年最低分
            <a-input v-model="updateMajorForm.score3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年投档最低位次
            <a-input v-model="updateMajorForm.ranking3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            所在省
            <a-input v-model="updateMajorForm.province" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在省" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            所在市
            <a-input v-model="updateMajorForm.city" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在市" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            选科<br>
            <a-input v-model="updateMajorForm.subject" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在市" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            学费
            <a-input v-model="updateMajorForm.money" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入学费" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            类型层次
            <a-input v-model="updateMajorForm.level" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入学制" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            批次<br>
            <a-radio-group v-model="updateMajorForm.batch" style="padding: 5px 10px;border-bottom: 1px solid rgb(0,120,215);border-radius: 2px;margin-top: 5px;width: 100%;line-height: 30px;">
              <a-radio value="本科">本科</a-radio>
              <a-radio value="专科">专科</a-radio>
            </a-radio-group>
          </div>
        </div>
        <div style="text-align: right;padding: 5px 20px;">
          <a-button style="padding: 0 30px;" type="primary" :loading="isUpdating" @click="updateMajor">修改</a-button>
        </div>
      </div>
      <div v-if="rightPageId==1" style="width: 100%;height: 100%;">
        <div style="padding: 20px 20px;font-size: 14px;border-bottom: 1px solid var(--color-neutral-4);position: relative;padding-left: 55px;">
            <div style="padding: 20px 20px;position: absolute;left: 0;top: 0;cursor: pointer;" @click="rightPageId=0">
              <svg width="15" height="15" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.272 24l16.263 16.264a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0L11.03 25.414a2 2 0 010-2.828L28.706 4.908a1 1 0 011.414 0l1.415 1.414a1 1 0 010 1.415L15.271 24z" fill="currentColor"/></svg>
            </div>
              添加专业
        </div>
        <div style="width: 100%;padding: 20px 20px;height: calc(100% - 112px);overflow-y: scroll;">
          <div style="margin-bottom: 10px;">
            专业代码
            <a-input v-model="addMajorForm.majorCode" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入专业代码" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            专业名称
            <a-input v-model="addMajorForm.majorName" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入专业名称" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            院校代码
            <a-input v-model="addMajorForm.universityCode" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入院校代码" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            院校名称
            <a-input v-model="addMajorForm.universityName" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入院校名称" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年投档计划数
            <a-input v-model="addMajorForm.num1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年最低分
            <a-input v-model="addMajorForm.score1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(1) }}年投档最低位次
            <a-input v-model="addMajorForm.ranking1" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年投档计划数
            <a-input v-model="addMajorForm.num2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年最低分
            <a-input v-model="addMajorForm.score2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(2) }}年投档最低位次
            <a-input v-model="addMajorForm.ranking2" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年投档计划数
            <a-input v-model="addMajorForm.num3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档计划数'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年最低分
            <a-input v-model="addMajorForm.score3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年最低分'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            {{ subtractFromCurrentYear(3) }}年投档最低位次
            <a-input v-model="addMajorForm.ranking3" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" :placeholder="'请输入' + subtractFromCurrentYear(1) + '年投档最低位次'" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            所在省
            <a-input v-model="addMajorForm.province" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在省" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            所在市
            <a-input v-model="addMajorForm.city" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在市" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            选科<br>
            <a-input v-model="addMajorForm.subject" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入所在市" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            学费
            <a-input v-model="addMajorForm.money" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入学费" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            类型层次
            <a-input v-model="addMajorForm.level" style="height: 35px;margin-top: 5px;padding: 0 0;background-color: white;border: 0;border-bottom: 1px solid rgb(0,120,215);" placeholder="请输入学制" allow-clear></a-input>
          </div>
          <div style="margin-bottom: 10px;">
            批次<br>
            <a-radio-group v-model="addMajorForm.batch" style="padding: 5px 10px;border-bottom: 1px solid rgb(0,120,215);border-radius: 2px;margin-top: 5px;width: 100%;line-height: 30px;">
              <a-radio value="本科">本科</a-radio>
              <a-radio value="专科">专科</a-radio>
            </a-radio-group>
          </div>
        </div>
        <div style="text-align: right;padding: 5px 20px;">
          <a-button style="padding: 0 30px;" type="primary" :loading="isAdding" @click="addMajor">添加</a-button>
        </div>
      </div>
    </div>
    <div style="width: calc(100% - 420px);height: 100%;display: inline-block;float: left;border-radius: 5px;background-color: white;position: relative;">
      <div style="padding: 20px 20px;border-bottom: 1px solid var(--color-neutral-4);position: relative;">
          专业管理
      </div>
      <div style="padding: 20px 20px;margin-bottom: 10px;height: calc(100% - 56.75px);position: relative;">
      <div>
          <span>
            <div style="display: inline-block;width: calc(25% - 4px);">
              专业代码
              <a-input v-model="searchForm.majorCode" allow-clear style="border: 0px;border-bottom: 1px solid rgb(0,120,215);background-color: white;padding: 0 0;height: 35px;" placeholder="请输入专业代码"></a-input>
            </div>
          </span>
          <span style="margin-left: 5.3px;">
            <div style="display: inline-block;width: calc(25% - 4px);">
              专业名称
              <a-input v-model="searchForm.majorName" allow-clear style="border: 0px;border-bottom: 1px solid rgb(0,120,215);background-color: white;padding: 0 0;height: 35px;" placeholder="请输入专业名称"></a-input>
            </div>
          </span>
          <span style="margin-left: 5.3px;">
            <div style="display: inline-block;width: calc(25% - 4px);">
              院校代码
              <a-input v-model="searchForm.universityCode" allow-clear style="border: 0px;border-bottom: 1px solid rgb(0,120,215);background-color: white;padding: 0 0;height: 35px;" placeholder="请输入院校代码"></a-input>
            </div>
          </span>
          <span style="margin-left: 5.3px;">
            <div style="display: inline-block;width: calc(25% - 4px);">
              院校名称
              <a-input v-model="searchForm.universityName" allow-clear style="border: 0px;border-bottom: 1px solid rgb(0,120,215);background-color: white;padding: 0 0;height: 35px;" placeholder="请输入院校名称"></a-input>
            </div>
          </span>
        <div style="text-align: right;margin-top: 10px;margin-bottom: 10px;">
          <a-button :loading="isSearching" style="padding: 0 30px;" @click="()=>{
            searchForm.majorCode='';
            searchForm.majorName='';
            searchForm.universityCode='';
            searchForm.universityName='';
            getMajors();
          }">显示全部</a-button>
          <a-button style="padding: 0 30px;margin-left: 10px;" type="primary" :loading="isSearching" @click="getMajors">查找</a-button>
        </div>
        </div>
        <a-table v-model:selected-keys="selectedKeys" @row-click="(e)=>{
          // return;
          rightPageId=2;
          updateMajorForm=e;
          // updateMajorForm.subject=convertStringToArray(updateMajorForm.subject.toString());
          // updateMajorForm.focus=convertStringToArray(updateMajorForm.focus.toString());
          // updateMajorForm.firstRate=convertStringToArray(updateMajorForm.firstRate.toString());
        }" :loading="isSearching" :row-selection="{
      type: 'checkbox',
      showCheckedAll: true
    }" :data="majors" :columns="[
          {
            title:'专业代码',
            dataIndex:'majorCode'
          },
          {
            title:'专业名称',
            dataIndex:'majorName'
          },
          {
            title:'院校代码',
            dataIndex:'universityCode'
          },
          {
            title:'院校名称',
            dataIndex:'universityName'
          },
        ]" style="width: 100%;height: calc(100% - 103.09px);"></a-table>
      </div>
    </div>
 </div>
</template>

<script>
import { read, utils } from 'xlsx'
// const xlsx = XLSX
import axios from 'axios'
// import path from 'path'

export default{
  data(){
    return{
      rightPageId:0,
      addMajorForm:{
        majorCode:'',
        majorName:'',
        universityCode:'',
        universityName:'',
        num1:'0',
        score1:'0',
        ranking1:'0',
        num2:'0',
        score2:'0',
        ranking2:'0',
        num3:'0',
        score3:'0',
        ranking3:'0',
        province:'',
        city:'',
        subject:'',
        money:'',
        level:'',
        batch:'本科'
      },
      updateMajorForm:{
        majorCode:'',
        majorName:'',
        universityCode:'',
        universityName:'',
        num1:'0',
        score1:'0',
        ranking1:'0',
        num2:'0',
        score2:'0',
        ranking2:'0',
        num3:'0',
        score3:'0',
        ranking3:'0',
        province:'',
        city:'',
        subject:'',
        money:'',
        level:'',
        batch:''
      },
      addMajorFormModel:{
        majorCode:'',
        majorName:'',
        universityCode:'',
        universityName:'',
        num1:'0',
        score1:'0',
        ranking1:'0',
        num2:'0',
        score2:'0',
        ranking2:'0',
        num3:'0',
        score3:'0',
        ranking3:'0',
        province:'',
        city:'',
        subject:'',
        money:'',
        level:'',
        batch:'本科'
      },
      isAdding:false,
      searchForm:{
        majorCode:'',
        majorName:'',
        universityCode:'',
        universityName:''
      },
      majors:[],
      isSearching:false,
      isUpdating:false,
      importMajorsCurrentStep:1,
      importMajorsWarningText:'',
      importedMajorsNum:0,
      importMajorsNum:0,
      preData:[],
      currentImportFile:1,
      selectedKeys:[],
      isDeleting:false,
      isOnlineRefreshing:false,
    }
  },
  mounted(){
    this.getMajors();
  },
  methods:{
    onlineRefresh(){
      this.isOnlineRefreshing=true;
      axios.post("/api/v1/majors/onlineRefresh").then(res=>{
        this.isOnlineRefreshing=false
        if(res.data.status==1){
          //
        }else{
          //
        }
      })
    },
    uploadFile(e){
      console.log(e)
    },
    deleteAll(){
      this.isDeleting=true;
      var config = {
   method: 'post',
   url: '/api/v1/majors/deleteAll',
   headers: { 
      'Accept': '*/*', 
   }
};

axios(config)
.then((res) => {
    this.isDeleting=false;
   if(res.data.status==1){
    this.getMajors();
    this.rightPageId=0;
   }else{
    this.$message.error({
      content:'删除失败'
    })
   }
})
    },
    deleteSelected(){
      if(this.selectedKeys.length==0){
        this.$message.error({
          content:'未选择专业'
        })
        return;
      }
      this.isDeleting=true;
      var config = {
   method: 'post',
   url: '/api/v1/majors/deleteSelected?data=' + JSON.stringify(this.selectedKeys),
   headers: { 
      'Accept': '*/*', 
   }
};

axios(config)
.then((res) => {
  this.isDeleting=false;
   if(res.data.status==1){
    this.rightPageId=0;
    this.selectedKeys=[];
    this.getMajors();
   }else{
    this.$message.error({
      content:'删除失败'
    })
   }
})
    },
    isStringHaveMaformedChar(str){
      for(let i=0;i<str.length;i++){
        if(str.slice(i,i+1)=='%'){
          return true;
        }
      }
      return false;
    },
    cutString(str){
      for(let i=0;i<str.length;i++){
        if(str.slice(i,i+1)=='('){
          return str.slice(0,i);
        }
      }
    },
    getSizeSmallArr(arr,start){
      if(JSON.stringify(arr[start]).length<=8000){
        let re = [];
        re.push(arr[start]);
        let i = start + 1;
        while(arr[i]!=undefined && (JSON.stringify(re).length+JSON.stringify(arr[i]).length)<=8000){
          re.push(arr[i]);
          i+=1;
        }
        // for(let i1=0;i1<re.length;i1++){
        //   if(re[i1].majorName.length>20){
        //     for(let i2=0;i2<re[i1].majorName.length;i2++){
        //       if(re[i1].majorName.slice(i2,i2+1)=='('){
        //         re[i1].majorName=re[i1].majorName.slice(0,i2);
        //         break;
        //       }
        //     }
        //   }
        // }
        for(let i=0;i<re.length;i++){
          if(this.isStringHaveMaformedChar(re[i].majorName)){
            re[i].majorName=this.cutString(re[i].majorName);
          }
        }
        return re;
      }else{
        for(let i=0;i<arr[start].majorName.length;i++){
          if(arr[start].majorName.slice(i,i+1)=='('){
            arr[start].majorName=arr[start].majorName.slice(0,i);
            break;
          }
        }
        let re = [];
        re.push(arr[start]);
        if(re[re.length-1].majorName.length>100){
          for(let i=0;i<re[start].majorName.length;i++){
          if(re[start].majorName.slice(i,i+1)=='('){
            re[start].majorName=re[start].majorName.slice(0,i);
            break;
          }
          }
        }
        // for(let i1=0;i1<re.length;i1++){
        //   if(re[i1].majorName.length>20){
        //     for(let i2=0;i2<re[i1].majorName.length;i2++){
        //       if(re[i1].majorName.slice(i2,i2+1)=='('){
        //         re[i1].majorName=re[i1].majorName.slice(0,i2);
        //         break;
        //       }
        //     }
        //   }
        // }
        for(let i=0;i<re.length;i++){
          if(this.isStringHaveMaformedChar(re[i].majorName)){
            re[i].majorName=this.cutString(re[i].majorName);
          }
        }
        return re;
      }
      // let re = [];
      // for(let i1=start;i1<start+10;i1++){
      //   re.push(arr[i1]);
      //   if(re[re.length-1].majorName.length>50){
      //     for(let i=0;i<re[start].majorName.length;i++){
      //     if(re[start].majorName.slice(i,i+1)=='('){
      //       re[start].majorName=re[start].majorName.slice(0,i);
      //       break;
      //     }
      //     }
      //   }
      // }
      // return re;
    },
    importMajorBasicInfoToBackground(arr,start,resend){
      let presend = null;
      if(resend==undefined){
        presend = this.getSizeSmallArr(arr,start);
      }else{
        presend = resend;
      }
      var config = {
        method: 'post', 
        url: '/api/v1/majors/importInfos',
        headers: { 
            'Accept': '*/*', 
        },
        data : presend
      };
      
      axios(config)
      .then((res) => {
        if(res.data.status==2){
          this.importMajorBasicInfoToBackground(arr,start,presend);
        }else{
          this.importedMajorsNum+=presend.length;
        if(arr.length-1<=start+presend.length){
          this.importMajorsCurrentStep=3;
          this.getMajors();
        }else{
          this.importMajorBasicInfoToBackground(arr,start+presend.length);
        }
        }
        
      })
    },
    importMajorToBackground(arr,start){
      let presend = [];
      for(let i=start;i<start+50;i++){
        if(arr[i]==undefined){
          continue;
        }
        presend.push(arr[i]);
      }
      var config = {
        method: 'post',
        url: '/api/v1/majors/import',
        headers: { 
            'Accept': '*/*', 
        },
        data : presend
      };
      
      axios(config)
      .then(() => {
        this.importedMajorsNum+=presend.length;
        if(arr.length-1<=start+50){
          this.importMajorsCurrentStep=4;
          this.getMajors();
        }else{
          this.importMajorToBackground(arr,start+50);
        }
      })
    },
    readExcel0(e) {
      this.importMajorsWarningText='';
//  var that = this;
const files = e.target.files;
console.log(e.target.files)
// const formData = new FormData();
//   formData.append('file', files[0]);

//   // 创建Axios实例
//   const axiosInstance = axios.create();

//   // 发送POST请求
//   axiosInstance.post('/api/v1/file/upload', formData, {
//     headers: {
//       'Content-Type': 'multipart/form-data'
//     }
//   })
//     .then((response) => {
//       console.log(response.data);
//     })
//     .catch((error) => {
//       console.error(error);
//     });
// 如果没有文件名
if(files.length<=0){
return false;
}else if(!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())){
this.$Message.error('上传格式不正确，请上传xls或者xlsx格式');
return false;
}
this.importUniversityStep=2;
const fileReader = new FileReader();
fileReader.onload = (ev) => {
try {
const data = ev.target.result;
// 切换为新的调用方式
const workbook = read(data, {
type: 'binary'
});
// 取第一张表
const wsname = workbook.SheetNames[0];
// 切换为新的调用方式 生成json表格内容
const ws = utils.sheet_to_json(workbook.Sheets[wsname]);
console.log(ws);
// 后续为自己对ws数据的处理
    this.importMajorsCurrentStep=2;
    let pre = [];
    for(let i=0;i<ws.length;i++){
      let pres = {
    majorName:ws[i]['专业名称'],
    majorCode:ws[i]['专业代码'],
    universityName:ws[i]['院校名称'],
    universityCode:ws[i]['院校代码'],
    num1:ws[i][this.subtractFromCurrentYear(1) + '年投档计划数'],
    score1:ws[i][this.subtractFromCurrentYear(1) + '年最低分'],
    ranking1:ws[i][this.subtractFromCurrentYear(1) + '年投档最低位次'],
    num2:ws[i][this.subtractFromCurrentYear(2) + '年投档计划数'],
    score2:ws[i][this.subtractFromCurrentYear(2) + '年最低分'],
    ranking2:ws[i][this.subtractFromCurrentYear(2) + '年投档最低位次'],
    num3:ws[i][this.subtractFromCurrentYear(3) + '年投档计划数'],
    score3:ws[i][this.subtractFromCurrentYear(3) + '年最低分'],
    ranking3:ws[i][this.subtractFromCurrentYear(3) + '年投档最低位次'],
    province:ws[i]['所在省'],
    city:ws[i]['所在市'],
    subject:ws[i]['科目'],
    money:ws[i]['学费'],
    level:ws[i]['类型层次'],
    batch:ws[i]['批次'],
    detail:"",
  }
  // for(let i1=0;i1<ws[i]['专业名称'].length;i1++){
  //   if(ws[i]['专业名称'].slice(i1,i1+1)=='('){
  //     pres['majorName']=ws[i]['专业名称'].slice(0,i1);
  //     break;
  //   }
  // }
  pre.push(pres);
  }
  console.log(pre)
    this.importMajorsNum=pre.length;
    this.importedMajorsNum=0;
    this.importMajorBasicInfoToBackground(pre,0);
} catch (e) {
return false;
}
};
fileReader.readAsBinaryString(files[0]);
},
    readExcel(e) {
      this.importMajorsWarningText='';
//  var that = this;
const files = e.target.files;
// 如果没有文件名
if(files.length<=0){
return false;
}else if(!/\.(xls|xlsx)$/.test(files[0].name.toLowerCase())){
this.$Message.error('上传格式不正确，请上传xls或者xlsx格式');
return false;
}
this.importUniversityStep=2;
const fileReader = new FileReader();
fileReader.onload = (ev) => {
try {
const data = ev.target.result;
// 切换为新的调用方式
const workbook = read(data, {
type: 'binary'
});
// 取第一张表
const wsname = workbook.SheetNames[0];
// 切换为新的调用方式 生成json表格内容
const ws = utils.sheet_to_json(workbook.Sheets[wsname]);
console.log(ws);
// 后续为自己对ws数据的处理
// const checkItems = ['专业名称','专业代码','院校名称','院校代码','投档计划数','最低分','投档最低位次','投档计划数','最低分','投档最低位次','投档计划数','最低分','投档最低位次','备注','所在省','所在市','C9/985/211/省重点','一流大学/一流学科','院校性质'];
let flag = true;
// for(let i=0;i<checkItems.length;i++){
//   if(ws[0][checkItems[i]]==undefined){
//     flag=false;
//     this.importMajorsWarningText='表格中找不到'+checkItems[i]+'，所以文件不符合要求。';
//     break;
//   }
// }
let  pre = [];
for(let i=0;i<ws.length;i++){
  pre.push({
    majorName:ws[i]['专业名称'],
    majorCode:ws[i]['专业代码'],
    universityName:ws[i]['院校名称'],
    universityCode:ws[i]['院校代码'],
    num1:ws[i][this.subtractFromCurrentYear(1) + '年投档计划数'],
    score1:ws[i][this.subtractFromCurrentYear(1) + '年最低分'],
    ranking1:ws[i][this.subtractFromCurrentYear(1) + '年投档最低位次'],
    num2:ws[i][this.subtractFromCurrentYear(2) + '年投档计划数'],
    score2:ws[i][this.subtractFromCurrentYear(2) + '年最低分'],
    ranking2:ws[i][this.subtractFromCurrentYear(2) + '年投档最低位次'],
    num3:ws[i][this.subtractFromCurrentYear(3) + '年投档计划数'],
    score3:ws[i][this.subtractFromCurrentYear(3) + '年最低分'],
    ranking3:ws[i][this.subtractFromCurrentYear(3) + '年投档最低位次'],
    province:ws[i]['所在省'],
    city:ws[i]['所在市'],
    subject:ws[i]['选科'],
    money:ws[i]['学费'],
    year:ws[i]['学制'],
    focus:ws[i]['C9/985/211/省重点'],
    firstRate:ws[i]['一流大学/一流学科'],
    public:ws[i]['院校性质'],
  })
}
if(flag){
  this.importMajorsCurrentStep=3;
    this.importMajorsNum=this.preData.length;
    this.importedMajorsNum=0;
    this.currentImportFile=1;
    this.importMajorBasicInfoToBackground(this.preData,0);
    this.preData=pre;
}else{
  return;
}

} catch (e) {
return false;
}
};
fileReader.readAsBinaryString(files[0]);
},
    updateMajor(){
      this.isUpdating=true;
      var config = {
   method: 'post',
   url: '/api/v1/majors/update?data=' + JSON.stringify(this.updateMajorForm),
   headers: { 
      'Accept': '*/*', 
   }
};

axios(config)
.then((res) => {
  this.isUpdating=false;
   if(res.data.status==1){
    this.rightPageId=0;
    this.getMajors();
   }else{
    this.$message.error({
      content:res.data.content
    })
   }
})
    },
    convertStringToArray(str) {
  // 使用逗号作为分隔符将字符串分割为数组
  var arr = str.split(',');

  // 使用map方法对数组中的每个元素进行处理，去除首尾的空格
  arr = arr.map(function(item) {
    return item.trim();
  });

  return arr;
},
    getMajors(){
      this.isSearching=true;
      var config = {
   method: 'get',
   url: '/api/v1/majors/search?data=' + JSON.stringify(this.searchForm),
   headers: { 
      'Accept': '*/*', 
   }
};

axios(config)
.then((res) => {
   if(res.data.status==1){
    this.majors=res.data.results;
    for(let i=0;i<this.majors.length;i++){
      this.majors[i]['key']=this.majors[i].universityCode + this.majors[i].majorCode;
    }
    this.isSearching=false;
   }else{
    this.$message.error({
      content:'查询失败'
    })
    this.isSearching=false;
   }
})
    },
    addMajor(){
      if(this.addMajorForm.majorCode==''){
        this.$message.error({
          content:'请输入专业代码'
        })
        return;
      }
      if(this.addMajorForm.majorName==''){
        this.$message.error({
          content:'请输入专业名称'
        })
        return;
      }
      if(this.addMajorForm.universityCode==''){
        this.$message.error({
          content:'请输入院校代码'
        })
        return;
      }
      if(this.addMajorForm.universityName==''){
        this.$message.error({
          content:'请输入院校名称'
        })
        return;
      }
      if(this.addMajorForm.province==''){
        this.$message.error({
          content:'请输入所在省'
        })
        return;
      }
      if(this.addMajorForm.city==''){
        this.$message.error({
          content:'请输入所在市'
        })
        return;
      }
      if(this.addMajorForm.money==''){
        this.$message.error({
          content:'请输入学费'
        })
        return;
      }
      if(this.addMajorForm.year==''){
        this.$message.error({
          content:'请输入学制'
        })
        return;
      }
      if(this.addMajorForm.public==''){
        this.$message.error({
          content:'请输入院校性质'
        })
        return;
      }
      this.isAdding=true;
      var config = {
        method: 'post',
        url: '/api/v1/majors/add?data=' + JSON.stringify(this.addMajorForm),
        headers: { 
            'Accept': '*/*', 
        }
      };

      axios(config)
      .then((res) => {
        if(res.data.status==1){
          this.isAdding=false;
          this.addMajorForm=this.addMajorFormModel;
        }else{
          this.$message.error({
            content:'添加失败'
          })
        }
      })
    },
    subtractFromCurrentYear(number) {
      var currentYear = new Date().getFullYear();
      return currentYear - number;
    }
  },
  props:{

  },
}
</script>

<style scoped>

.right-button svg{
  position: absolute;
  right: 15px;
  top: 15px;
}

.right-button:hover{
  background-color: rgb(242,242,242);
}

.right-button{
  width: 100%;
  padding: 15px 15px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 15px;
  position: relative;
  margin-bottom: 5px;
}

</style>